/* @author Stone, at Midea and GDOU
   @date March to May, 2021
   @brief common definitions about BLDC Driver
*/

#ifndef BOARDCOMMON_H
#define BOARDCOMMON_H
#include <Arduino.h>

// pin configuration in Arduino Nano
#define INH_A    2
#define IN_A     3
#define INH_B    4
#define IN_B     5
#define INH_C    6
#define IN_C     7

#define HALL_A   8
#define HALL_B   10
#define HALL_C   11

// current sense pin of BTN 8982
#define I_A A3
#define I_B A2
#define I_C A1

// system voltage
#define V_SYS_PIN A0

#define PWM_PIN  9

// others 
#define PWM_PERIOD 200  // micro seconds
#define N_INTERVALS 5   // length of the array to stroe time intervals

typedef enum MotorDir {
    MotorForward, MotorBackward
} MotorDir;

extern const int INH[];
extern const int IN[];
extern const int HALL[];
extern const byte steps[6][6];
extern const byte halls[6][3];


void BLDC_Init();
void BLDC_Update();
void BLDC_SetDir(MotorDir dir);
void BLDC_SetPwmDuty(uint16_t);
float BLDC_ReadSpeed();
float BLDC_ReadSysVolt();
void BLDC_ReadCurrent(uint16_t *ia, uint16_t *ib, uint16_t *ic);

#endif  // BOARDCOMMON_H
